<?php

class APIDefault
{
	protected $_api;
	protected $_request;
	protected $_response;
	
	public function __construct($api)
	{
		$this->_api = $api;
		$this->_request = $this->_api->_request;
		$this->_response = $this->_api->_response;
	}
	
	/** 
	* Default method
	* @http_method post get put
	*/
	public function _default()
	{
		$this->_api->response(404, '');
	}
	
	protected function response($status = 200, $data = null)
	{
		$this->_api->response($status, $data);
	}
	
	protected function email(&$errors)
	{
		if(!isset($errors))
			$errors = array();
		$email = $this->_request->email;
		if(!filter_var($email, FILTER_VALIDATE_EMAIL))
			$errors[] = "Invalid Email Address '$email'.";
		return $email;
	}
	
	protected function femail(&$errors)
	{
		if(!isset($errors))
			$errors = array();
		$email = $this->_request->femail;
		if(!filter_var($email, FILTER_VALIDATE_EMAIL))
			$errors[] = "Invalid Email Address";
		return $email;
	}
	
	protected function name(&$errors)
	{
		if(!isset($errors))
			$errors = array();
		$full_name = $this->_request->name;
		if(!isset($full_name) || empty($full_name))
			$errors[] = "Invalid Full Name";
		return $full_name;
	}
	
	protected function full_name(&$errors)
	{
		if(!isset($errors))
			$errors = array();
		$full_name = $this->_request->full_name;
		//if(!isset($login) || empty($login) || strlen($login) < 5 || strlen($login) > 15)
			//$errors[] = "Invalid Login";
		return $full_name;
	}
	
	protected function key(&$errors)
	{
		if(!isset($errors))
			$errors = array();
		$key = $this->_request->key;
		if(!isset($key) || empty($key))
			$errors[] = "Invalid Key";
		return $key;
	}
	
	protected function password(&$errors)
	{
		if(!isset($errors))
			$errors = array();
		$pwd = $this->_request->password;
		if(!isset($pwd) || empty($pwd) || strlen($pwd) < 6 || strlen($pwd) > 15)
			$errors[] = "Invalid Password";
		return $pwd;
	}
	
	protected function page()
	{
		$page = (int)$this->_request->page;
		if(!isset($page))
			$page = 1;
		return $page;
	}
}